package cn.com.yto56.coresystem.logic.msg.soa.dao.impl;

import cn.com.yto56.coresystem.common.msg.util.SysConst;
import cn.com.yto56.coresystem.common.msg.util.db.BaseJdbcUtil;
import cn.com.yto56.coresystem.common.msg.util.db.dao.annotation.JdbcDao;
import cn.com.yto56.coresystem.logic.msg.soa.dao.ISysInfoDao;

import java.util.*;

/**
 * Created by wangrui on 2017/2/15.
 */
@JdbcDao(dataSource = "msg_database")
public class SysInfoDaoImpl extends BaseJdbcUtil implements ISysInfoDao {

    @Override
    public String getAppId(String systemName, String systemInfo) {
        String result = "";
        Map map = new HashMap();
        map.put("yto_msg_sys_systemName", systemName);
        map.put("yto_msg_sys_systemInfo", systemInfo);
        if (checkForUpdate(SysConst.T_MSG_SYSINFO, map)) {
            String appId = UUID.randomUUID().toString();
            map.put("yto_msg_appId", appId);
            map.put("create_time", new Date());
            int t = insertData(SysConst.T_MSG_SYSINFO, map);
            if (t > 0) {
                result = appId;
            }
        }
        return result;
    }

    @Override
    public String getId(String appId) {
        String result = null;
        String sql = "select id from " + SysConst.T_MSG_SYSINFO + " where yto_msg_appId=?";
        List args = new ArrayList();
        args.add(appId);
        List<Map<String, Object>> resultData = query(sql, args);
        if (resultData != null && resultData.size() > 0) {
            result = String.valueOf(resultData.get(0).get("id"));
        }
        return result;
    }
}
